import { defHttp } from '@/utils/http/axios';
import { IFieldLibraryAddData, IFieldListResult } from './type';

enum Api {
  list = '/admin/custom-field-library/sys/list',

  fieldTypeList = '/admin/custom-form-item-type/list',
  fieldCategoryList = '/admin/custom-field-library/fieldCategory/list',
  fieldLibraryAdd = '/admin/custom-field-library/add',
  fieldLibraryUpdate = '/admin/custom-field-library/update',
  fieldLibraryDel = '/admin/custom-field-library/del',
}

/**
 * @description 列表
 * @date
 * @export
 * @param
 */
export function List(params) {
  return defHttp.get<IFieldListResult[]>({
    url: Api.list,
    params,
  });
}

/**
 * @description 字段类型列表
 * @date
 * @export
 * @param
 */
export function FieldTypeList() {
  return defHttp.get({
    url: Api.fieldTypeList,
  });
}

/**
 * @description 字段来源列表
 * @date
 * @export
 * @param
 */
export function FieldCategoryList() {
  return defHttp.get({
    url: Api.fieldCategoryList,
  });
}

/**
 * @description 新增字段
 * @date
 * @export
 * @param
 */
export function FieldLibraryAdd(data: IFieldLibraryAddData) {
  return defHttp.post({
    url: Api.fieldLibraryAdd,
    data,
  });
}

/**
 * @description 编辑字段
 * @date
 * @export
 * @param
 */
export function FieldLibraryUpdate(data: IFieldLibraryAddData) {
  return defHttp.post({
    url: Api.fieldLibraryUpdate,
    data,
  });
}

/**
 * @description 删除字段
 * @date
 * @export
 * @param
 */
export function FieldLibraryDel(id) {
  return defHttp.post({
    url: Api.fieldLibraryDel + `/${id}`,
  });
}
